package cn.edu.zafu.bigdata.x.yaojy;
import java.io.*;
import java.net.*;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        String serverName = "192.168.16.2";
        int port = 12345;

        try(Socket client = new Socket(serverName,port);
            BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
            PrintWriter out = new PrintWriter(client.getOutputStream(),true);
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))){
            System.out.println("Connected to the server");
            String userInput;
            while ((userInput = stdIn.readLine()) != null) {
                out.println(userInput);
                System.out.println("Server: " + in.readLine());
            }
        }catch (UnknownHostException e){
            System.err.println("Unknown host:" + e.getMessage());
            System.exit(1);
        }catch (IOException e){
            System.err.println("Could't get I/O for the connection to the server:" +e.getMessage());
            System.exit(1);
        }
    }
}
